class Container {
    constructor(list) {
        this.list = list
    }
    // 生成遍历器
    getIterator() {
        return new Iterator(this)
    }
}

class Iterator {
    constructor(container) {
        this.list = container.list;
        this.index = 0;
    }
    next() {
        if (this.hasNext()) {
            return this.list[this.index++];
        }
        return null;
    }
    hasNext() {
        if (this.index < this.list.length) return true;
        return false;
    }
}

// 测试代码
let container = new Container([1, 2, 3, 4, 5]);
let iterator = new Iterator(container);
while (iterator.hasNext()) {
    console.log(iterator.next())
}